package com.moonshineproject.plugin.actionscript.as3parser.parsers
{
	import com.moonshineproject.plugin.actionscript.as3parser.vo.PackageVO;
	
	import flash.filesystem.File;
	
	public class AS3ParserUtil
	{
		public static function packageNameToPath(name:String):String
		{
			if (!name || name == "") return "";
			return name.split(".").join(File.separator);
		}
		
		public static function findOrCreatePackage(pkg:String, global:PackageVO):PackageVO
		{
			if (pkg == global.name) return global;
			
			// TODO: Speed up this loop
			var currentPackage:PackageVO = global;
			var newPackage:PackageVO;
			
			var split:Array = pkg.split(".");
			for each (var part:String in split)
			{
				newPackage = currentPackage.getPackage(part);
				if (!newPackage)
				{
					newPackage = currentPackage.createPackage(part);
				}
				currentPackage = newPackage;
			}
			
			return currentPackage;
		}
		
	}
}